﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Compiler
{
    public class EbnfAssign : EbnfNode
    {
        EbnfMeta head;
        EbnfNode tail;
        IntegerNode productionId;

        public EbnfAssign(EbnfMeta head, EbnfNode tail)
        {
            this.head = head;
            this.tail = tail;
            this.productionId = new IntegerNode("0");
        }

        public EbnfAssign(IntegerNode productionId, EbnfMeta head, EbnfNode tail)
        {
            this.productionId = productionId;
            this.head = head;
            this.tail = tail;
        }

        static int id = 1;
        public override void Convert2Grammar(Ebnf2GrammarConvertData data)
        {
            Production prod = new Production(productionId.value,
                                             data.GetNonterminal(head.lexeme),
                                             tail.ConstructProductionTail(data));

            data.AddProduction(prod);
        }

        public override EbnfNode Expand(Stack<EbnfAssign> Open)
        {
            tail = tail.Expand(Open);
            return this;
        }

        public override string ToString()
        {
            return head.ToString() + " ::= " + tail.ToString();
        }
    }
}
